package com.zry.generator.config;

import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import org.springframework.context.annotation.Bean;

/**
 * @author zry
 * @create 2023-09-09 20:29
 */
public class MybatisPlusGeneratorConfig {

    /**
     * 全局配置
     */
    @Bean
    public GlobalConfig globalConfig() {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir("/src/main/java");
        globalConfig.setAuthor("赵睿宇");
        globalConfig.setOpen(false);
        // xml 开启 BaseResultMap
        globalConfig.setBaseResultMap(true);
        // 日期格式 采用 Date
        globalConfig.setDateType(DateType.ONLY_DATE);
        return globalConfig;
    }

    /**
     * mybatis-plus 数据源配置
     */
    @Bean
    public DataSourceConfig dataSourceConfig() {
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/cloud?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("123456");
        // dsc.setDbQuery(new MySqlQuery() {
        //     @Override
        //     public String[] fieldCustom() {
        //         return new String[]{"Null", "Default", "Extra"};
        //     }
        // });
        return dataSourceConfig;
    }


}
